<?php
	session_start();

	include("mysql_connect.php");
	
	if( $_POST['Neighborhood'] == "Any" || $_POST['Neighborhood'] == "")
	{
		if( $_POST['City'] == "Any" || $_POST['City'] == "")
		{
			$strKey = ' WHERE tbCF.Currency > 0';
		}
		else
		{
			$strKey = ' WHERE City LIKE "'.$_POST['City'] . '" AND tbCF.Currency > 0';
		}
	}
	else
	{
		$strKey = ' WHERE Neighborhood LIKE "'.$_POST['Neighborhood'] . '" AND tbCF.Currency > 0';
	}
//	echo $strKey . "<br/>";
	$strSqlCommand = "SELECT MAX(Currency), MIN(Currency)
						FROM ResidentialProperty tbRP
						LEFT JOIN Listing  tbLT			ON tbRP.Listing_idListing = tbLT.idListing
						LEFT JOIN ListingData tbLD		ON tbLT.ListingData_idListingData = tbLD.idListingData
						LEFT JOIN CurrencyFormat tbCF	ON tbLD.Price = tbCF.idCurrencyFormat
						LEFT JOIN StreetAddress  tbSA	ON tbLT.StreetAddress_idStreetAddress = tbSA.idStreetAddress" . $strKey;
		
	//echo $strSqlCommand;
		
	$result = mysql_query($strSqlCommand);
	$rowMax = @mysql_fetch_array($result);

	echo $rowMax['0']. " " . $rowMax['1'] . " " . pow( 10, strlen( $rowMax['0'] / 5) ) ."<br/>";
	
	$_SESSION['nRange'] = pow( 10, strlen( $rowMax['0'] ) - 1) ;
	echo '<option selected="selected" value="-1">Any</option>';
//	echo 'Any<br>';

	if( $rowMax['0'] != $rowMax['1'] )
	{
		//echo $strSqlCommand;
		for( $i = 0 ; $i < 4 ; $i++ )
		{// URL, Price,idListing
			echo '<option value="'.$i.'">'. ( $_SESSION['nRange'] * $i)  .' - '. $_SESSION['nRange'] * ($i+1).' </option>';
//			echo ($nRange * $i)  .' - '.  $nRange * ($i+1).' <br/>';
		}
		echo '<option value="4">'. ( $_SESSION['nRange'] * 4)  .' + </option>';
//		echo ( $nRange * 4)  .' + <br/>';
	}
?>